import axios from "axios";

import { GET_TOKEN } from "../actionTypes";

export const getUserTokenAction = (data) => ({
  type: GET_TOKEN,
  data,
});

const delayFunc2 = (time = 1000, extraParams = "") => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(extraParams);
    }, time);
  });
};

// 异步方式获取数据
export const getUserTokenAction2 = (params) => {
  return async (dispatch) => {
    // 这里就模拟请求接口了
    const data = await delayFunc2(1000, params);
    if (data) {
      dispatch({
        type: GET_TOKEN,
        data,
      });
      return Promise.resolve(data);
    } else {
      return Promise.reject("请求失败");
    }
  };
};
